
from selenium import webdriver
from time import sleep
import pdfkit
import os
def txtToPdf(file):
    path_wk = r"./wkhtmltox-0.12.6-1.msvc2015-win64.exe"
    config = pdfkit.configuration(wkhtmltopdf=path_wk)
    options = {
        'page-size': 'A2',   #页面大小
        'minimum-font-size': 15,
        'margin-top': '0.75in',  #边框填充(inch,基本单位)
        'margin-right': '0.75in',
        'margin-bottom': '0.75in',
        'margin-left': '0.75in',
        'encoding': "UTF-8",   #编码
    }


    filename = os.path.splitext(file)[0]

    with open("file","r") as f:
        content = f.readlines
        f.close()
    a = ""
    for i in content:
        a = a + i
    pdfkit.from_string(a,filename + '.pdf',configuration=config,options=options)

if __name__ == '__main__':

    url ='https://asia.tools.euroland.com/tools/pressreleases/?companycode=ky-dafa&lang=zh-CN#'
    bro=webdriver.Chrome(executable_path='./chromedriver')
    bro.get(url=url)
    btn = bro.find_element_by_link_text('全部')
    btn.click()
    page_text = bro.page_source
    with open('11.txt','w',encoding='utf-8') as f :
        f.write(page_text)
    txtToPdf('./11.txt')